const App = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 选项卡标示
    dataType: 'not_use',

    // 列表高度
    swiperHeight: 0,

    // 列表
    list: [],
    // show
    notcont: false,
    status: 0,
    hasFubiaoPromission: false,
    hasZhuBiaoPromission: false,
    quId:'',
    quName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("区id",options)
    // 设置swiper的高度
    this.setSwiperHeight();
    let hasFubiaoPromission = wx.getStorageSync('hasFubiaoPromission')
    let hasZhuBiaoPromission = wx.getStorageSync('hasZhuBiaoPromission')
    this.setData({
      hasFubiaoPromission: hasFubiaoPromission,
      hasZhuBiaoPromission: hasZhuBiaoPromission
    })
    this.setData({
      quId: options.id,
      quName:options.quName
    })
    wx.setNavigationBarTitle({
      title: options.quName,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取优惠券列表
    this.GetUserBaoMingList();
  },

  /**
   * 获取列表
   */
  GetUserBaoMingList: function () {
    let _this = this
    var status;
    wx.request({
      url: App.api_test + 'GetJieDao',
      header: {
        'content-type': 'application/JSON',
      },
      method: 'POST',
      data: {
        openId: wx.getStorageSync('openid'),
        userId: wx.getStorageSync('user_id'),
        quId:_this.data.quId
      },
      success(res) {
        console.log('街道历史', res)
        _this.setData({
          list: res.data,
          notcont: false
        });
      },
      fail(res) {
        console.log('城中村附件历史异常', res);
      }
    })
  },
  /**
   * 设置swiper的高度
   */
  setSwiperHeight: function () {
    // 获取系统信息(拿到屏幕宽度)
    // let query = wx.createSelectorQuery();
    // let height=0;
    // query.select('.content').boundingClientRect(rect=>{
    //   height = rect.height;
    // }).exec()
    // console.log("按钮高度",height);
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 80) + 1, // tap高度
      swiperHeight = systemInfo.windowHeight; // swiper高度
    // swiperHeight = systemInfo.windowHeight-height; // swiper高度
    // swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      swiperHeight
    });
  },

  delete(e) {
    let _this = this;
    wx.showModal({
      content: '确定要删除吗？',
      title: '删除',
      success: (ee) => {
        if (ee.confirm) {
          wx.request({
            url: App.api_test + 'DelChengZhongCunFuBiao',
            header: {
              'content-type': 'application/JSON',
            },
            method: 'POST',
            data: {
              id: e.currentTarget.dataset.id
            },
            success(res) {
              console.log('城中村附件删除', res)
              wx.showToast({
                title: res.data,
              })
              _this.GetUserBaoMingList()
            },
            fail(res) {
              console.log('城中村附件删除异常', res);
            }
          })
        }
      }
    })
  },
  go(e) {
    var url = '/pages/dongbiao/index';
    wx.navigateTo({
      url: `${url}?id=${e.currentTarget.dataset.id}&name=${e.currentTarget.dataset.name}`,
    })
  },
  add(e) {
    wx.navigateTo({
      url: '/pages/dongbiao_add/index',
    })
  },
  jiandong(e){
    let app = getApp()
    app.globalData.ChengZhongCunId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/dongbiao_c/index?id=${e.currentTarget.dataset.id}`,
    })
  }

});